package com.ruoyi.framework.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

@Component
public class MyAuthenticationProvider implements AuthenticationProvider {
    @Autowired
    private UserDetailsService userDetailsService;

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        UserDetails ud = userDetailsService.loadUserByUsername("admin");
        return new MyUsernamePasswordAuthenticationToken(ud,authentication.getCredentials(),ud.getAuthorities());
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return MyUsernamePasswordAuthenticationToken.class.isAssignableFrom(aClass);
    }
}
